package com.ruoyi.order.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.messaging.Message;
import com.alibaba.fastjson.JSON;

import java.util.Map;

@Component
public class OrderMessageListener {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RabbitListener(queues = "order.create.queue")
    public void handleOrderCreate(Message message) {
        // 处理订单创建消息
        try {
            Map<String, Object> orderInfo = JSON.parseObject(new String(message.getHeaders().get("orderInfo").toString()), Map.class);
            // TODO: 实现订单创建逻辑
        } catch (Exception e) {
            // 处理异常，可以重试或记录失败日志
        }
    }

    @RabbitListener(queues = "order.cancel.queue")
    public void handleOrderCancel(Message message) {
        // 处理订单取消消息
        try {
            String orderNo = new String(message.getHeaders().get("orderInfo").toString());
            // TODO: 实现订单取消逻辑
        } catch (Exception e) {
            // 处理异常
        }
    }
}
